<template>
  <div class="login-container">
    <div class="logo" />
    <div class="form">
      <p style="color: #1E2023 ;font-size: 25px; margin-left: 20px;">智慧园区-登录</p>
      <el-card shadow="never" class="login-card">
        <!--登录表单-->
        <el-form ref="loginForm" :rules="loginRules" :model="loginForm">
          <!-- 账号 -->
          <span style="font-size: 12px;">账号</span>
          <el-form-item prop="username">
            <el-input v-model="loginForm.username" placeholder="请输入手机号" />
          </el-form-item>
          <!-- 密码 -->
          <span style="font-size: 12px;">密码</span>
          <el-form-item prop="password">
            <el-input v-model="loginForm.password" placeholder="请输入密码" show-password />
          </el-form-item>
          <!-- 模型uuid -->
          <span style="font-size: 14px;">模型uuid:</span>
          <el-form-item prop="moxing">
            <el-input v-model="loginForm.moxing" placeholder="请输入id" show-password />
          </el-form-item>
          <!-- 用户平台使用协议 -->
          <el-form-item prop="checked">
            <el-checkbox v-model="loginForm.checked">用户平台使用协议</el-checkbox>
          </el-form-item>
          <!-- 登录按钮 -->
          <el-form-item>
            <el-button type="primary" style="width: 350px;" @click="login">登录</el-button>
          </el-form-item>
        </el-form>
        <!-- 注意文字 -->
        <p style="color: red; font-size: 14px; width: 350px;">仅用于IT培训教学使用,为保障您的个人信息安全,请勿向平台录入任何个人敏感信息(如手机号,身份证号等) !</p>
      </el-card>
    </div>
  </div>
</template>
<script>

export default {
  name: 'Login',
  data() {
    return {
      // 登录表单的校验的规则
      loginRules: {
        username: [
          { required: true, message: '请输入账号', trigger: 'change' },
          { message: '账号格式不正确', trigger: 'change' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'change' },
          { min: 6, max: 16, required: true, message: '密码需要为6-16位之间', trigger: 'change' }
        ],
        moxing: [
          { required: true, message: '请输入ID', trigger: 'change' }
          // { min: 6, max: 16, required: true, message: 'id需要为6-16位之间', trigger: 'change' }
        ],
        checked: [{
          // rule规则
          // value值
          // callback
          validator: (rule, value, callback) => {
            value ? callback() : callback(new Error('请勾选用户平台协议'))
          }
        }]
      },
      // 绑定数据对象
      loginForm: {
        checked: process.env.NODE_ENV === 'development', // 是否同意平台协议
        username: process.env.NODE_ENV === 'development' ? 'demo' : '', // 手机号 和接口文档对应
        password: process.env.NODE_ENV === 'development' ? 'Hmzs%001' : '', // 密码 和接口文档对应
        moxing: process.env.NODE_ENV === 'development' ? '66ea8d2a-7416-4be5-ba7e-c030cf88b3f3' : '' // ID 和接口文档对应
      }
    }
  },
  // 登录事件函数
  methods: {
    login() {
      this.$refs.loginForm.validate(async(isOK) => {
        if (isOK) {
          await this.$store.dispatch('user/login', { username: this.loginForm.username, password: this.loginForm.password })
          this.$router.push('/')
        }
      })
    }
  }
}
</script>
<style lang="scss">
.login-container {
  display: flex;
  align-items: stretch;
  height: 100vh;
  .logo {
    flex: 3;
    background: rgba(38, 72, 176) url(../../assets/common/login-bg-e4ea539c.svg)
      no-repeat center / cover;
    border-top-right-radius: 60px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    padding: 0 100px;
    .icon {
      background: url(../../assets/common/logo.png) no-repeat 70px center /
        contain;
      width: 300px;
      height: 50px;
      margin-bottom: 50px;
    }
    p {
      color: #fff;
      font-size: 18px;
      margin-top: 20px;
      width: 300px;
      text-align: center;
    }
  }
  .form {
    flex: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-left: 176px;
    .el-card {
      border: none;
      padding: 0;
    }
    h1 {
      padding-left: 20px;
      font-size: 24px;
    }
    .el-input {
      width: 350px;
      height: 44px;
      .el-input__inner {
        background: #f4f5fb;
      }
    }
    .el-checkbox {
      color:#606266;
    }
  }
}
</style>
